$(function(){
    obj.init();
});

var obj = new JsFun();
function JsFun(){
    'use strict';
    return {
        dataGrid: null,
        params: {
            schoolId: null
        },
        init: function () {
            this.params.schoolId = xhTool.getQuery('schoolId');

            this.dataGrid = new xhDataGrid($('#list'), 'Appserver/getSchoolApp/true', {schoolId: this.params.schoolId});
            this.dataGrid.parseToolbar().init().activeBtn(null, $('#bt_list_version_stats'));

            this.listener();
        },
        listener: function () {
            var $this = this;
            //设置权限
            $('#bt_list_permission').menubutton({
                menu: '#menu_permission'
            });
            //查看版本统计
            $('#bt_list_version_stats').click(function () {
                 if (xhExtra.buttonDisabled($(this))) return false;
                 obj.funObj().showVersionStats();
            });
        },
        funObj: function(){
            var $this = this;
            return {
                setPermission: function (permission, msg) {
                    var packageNames = $this.dataGrid.getSelectValues('packageName');
                    if (!packageNames) {
                        window.top.xhTop.showError('未选中记录！');
                        return false;
                    }
                    xhExtra.askChangeStatus(
                        'Appserver/setSchoolAppPermission',
                        {schoolId: $this.params.schoolId, permission: permission, packageNames: packageNames},
                        $this.dataGrid,
                        msg
                    );
                },
                showVersionStats: function () {
                    var packageName = $this.dataGrid.getSelectValue('packageName');
                    window.top.xhTop.showModal({
                        title: '版本统计-' + $this.dataGrid.getSelectValue('appName'),
                        content: xhTool.getFrameString('/Appserver/schoolAppVersion', {schoolId: $this.params.schoolId, packageName: packageName}, 500)
                    });
                }
            }
        }
    }
}
